package top.fangw.common.mybatis.handler;


import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import net.sf.jsqlparser.expression.Expression;
import org.springframework.stereotype.Component;
import top.fangw.common.mybatis.annotation.DataPermission;

import java.lang.reflect.Method;

/**
 * @description: 数据权限处理器
 * @author: fgw
 * @createDate: 2024/1/8
 */
@Component
public class CustomizeDataPermissionHandler  implements DataPermissionHandler {

    @Override
    public Expression getSqlSegment(Expression where, String mappedStatementId) {

        try {
            Class<?> clazz  = Class.forName(mappedStatementId.substring(0, mappedStatementId.lastIndexOf(".")));
            String methodName = mappedStatementId.substring(mappedStatementId.lastIndexOf(".") + 1);
//            Method declaredMethod = clazz.getDeclaredMethod(methodName);
//            DataPermission annotation = declaredMethod.getAnnotation(DataPermission.class);
//            String s = annotation.deptAlias();
//            System.out.println("s = " + s);
            System.out.println("where = " + where);
            System.out.println("mappedStatementId = " + mappedStatementId);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        return where;
    }
}
